﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{       
    public class WGGINVReport : BaseReport
    {
        string strCompany = "HLT";
        string strExcelFile = "";
        string sheetName = "";
        string Standard = "WGGINV";
        string filePath = @"C:\intex.w\Report\HLT\HLTPlanningReport.xls";
        public WGGINVReport()
            : base()
        {
        }
        public WGGINVReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        { 
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            strExcelFile = @"HLT\HLTInventory.xls";
            #region Excel  columns 
            columns.Add("ARTICLE");
            columns.Add("WBEWBUCHDAT");
            columns.Add("WBEWBS");
            columns.Add("FUNCTION");
            columns.Add("WBBDPART"); 
            columns.Add("WBEWLO");
            columns.Add("STARTQTY");
            columns.Add("STARTPCNUM");
            columns.Add("WBEWMTR");
            columns.Add("PCNUM");
            columns.Add("ENDPCNUM");
            columns.Add("ENDQTY");  
            #endregion
        }
        public void FillInExcelData(ArrayList columns, DataTable dtSoruce)
        { 
            try
            {
                int x = 3, y = 1;
                foreach (DataRow dataRow in dtSoruce.Rows)
                {
                    y = 1;
                    foreach (DataColumn dcTemp in dtSoruce.Columns)
                    {
                        exAgent.SetCellValue(x, y, dataRow[dcTemp.ColumnName].ToString());
                        y++;
                    }
                    x++;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void WriteExcelReport(string fileType)
        {
            string filename = "";
            string sheetName = "";
            string Standard = "WBINV";
            strExcelFile = @"HLT\HLTInventory.xls";
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            string filedate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            filename = @"Warehouse\产品进出流水帐.xls";
            sheetName = DateTime.Now.ToShortTimeString().Replace(@":", ""); 
            exAgent.CreateNewSheet(filename, Standard, sheetName);
            FillInData(columns, dsSource.Tables["WBBEW"],5,2);
            base.WriteExcelReport(fileType);        
        }
    }
}
